//
//  YaoPinPopUpView.swift
//  ANOA
//
//  Created by 邱仙凯 on 2021/9/7.
//  Copyright © 2021 aowang. All rights reserved.
//

import UIKit
 
class YaoPinPopUpView: UIView {

    lazy var bg:UIView = {
       let v = UIView()
        v.backgroundColor = .black
        v.alpha = 0.3
        return v
    }()
    lazy var contentV:UIView = {
        let v = UIView()
        v.backgroundColor = .white
        v.layer.cornerRadius = 5
         return v
    }()
    lazy var closeBtn:UIButton = {
       let v = UIButton()
        v.setImage(UIImage(named:"guanbi"), for: .normal)
        return v
    }()
     
    var lastLab:UILabel?
    lazy var attributes:[NSAttributedString.Key : NSObject] = {
        let paraph = NSMutableParagraphStyle()
        //将行间距设置为
        paraph.lineSpacing = 4
        //样式属性集合
        let titleAttributes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 15),
                           NSAttributedString.Key.paragraphStyle: paraph]
        return titleAttributes
    }()
    
    var one = ZtbContentModel(JSON:["":""])! {
      didSet {
        for i in 0..<11 {
 
            let lab = UILabel()
            lab.font = UIFont.systemFont(ofSize: 15)
            let right = UILabel()
            right.font = UIFont.systemFont(ofSize: 15)
             contentV.addSubview(lab)
            contentV.addSubview(right)
            right.numberOfLines = 0
            if i ==  0 {
                 lab.text = "商品名:"
                 right.text = one.zGoodsName
            }
            if i ==  1 {
                 lab.text = "通用名:"
                 right.text = one.zGeneralName
            }
            if i ==  2 {
                 lab.text = "成分与含量:"
                right.text = one.zMainElement
            }
            if i ==  3 {
                 lab.text = "规格:"
                 right.text = one.zSpecification
            }
            if i ==  4 {
                 lab.text = "计价单位:"
                 right.text = one.zValuationUnit
            }
     
            if i ==  5 {
                 lab.text = "单价:"
                 right.text = one.zPrice
            }
            if i ==  6 {
                 lab.text = "批准文号:"
                 right.text = one.zApprovalNum
            }
            if i ==  7 {
                 lab.text = "保质期:"
                 right.text = one.zExpirationDate
            }
            if i ==  8 {
                 lab.text = "生产厂家:"
                 right.text = one.zManufacturer
            }
            if i ==  9 {
                 lab.text = "供应商:"
                 right.text = one.zSupplier
            }
            if i ==  10 {
                 lab.text = "产品说明:"
                 right.text = one.zProductInstructions
            }
            
            right.snp.makeConstraints { make in
                make.left.equalTo(contentV).offset(100)
                make.right.equalTo(contentV).offset(-5)
                if lastLab.isNone {
                    make.top.equalTo(contentV).offset(38)
                } else {
                    make.top.equalTo(lastLab!.snp.bottom).offset(4)
                 }
                if i == 10 {
                    make.bottom.equalTo(contentV).offset(-38)
                 }
              }
            lab.snp.makeConstraints { make in
                make.left.equalTo(contentV).offset(10)
                make.top.equalTo(right)
               }
             lastLab = right
        }
      }
    }
  
    override init(frame:CGRect) {
        super.init(frame: frame)
        bg.frame = self.bounds
        self.addSubview(bg)
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(tapAction))
         bg.addGestureRecognizer(tap)
 
        self.addSubview(contentV)
        contentV.snp.makeConstraints { make in
            make.left.equalTo(bg).offset(10)
            make.right.equalTo(bg).offset(-10)
             make.centerY.equalTo(bg)
        }
        contentV.addSubview(closeBtn)
        closeBtn.addTarget(self, action: #selector(tapAction), for: .touchUpInside)
        closeBtn.snp.makeConstraints { make in
            make.top.equalTo(contentV).offset(8)
            make.right.equalTo(contentV).offset(-8)
            make.width.equalTo(30)
            make.height.equalTo(30)
         }
 
    }
    @objc func tapAction() {
        self.removeFromSuperview()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
  

}
